package com.estate.owner.controller;

import com.estate.bean.Pet;
import com.estate.owner.service.PetService;
import com.estate.util.JsonResult;
import com.estate.util.ResultTool;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/pet")
public class PetController {

    @Resource
    private PetService petService;

    @GetMapping("/list/{petId}")
    public JsonResult findById(@PathVariable("petId") String petId) {
        return petService.findById(petId);
    }

    @PostMapping("/save")
    public JsonResult save(Pet pet) {
        log.info("pet:{}", pet);
        JsonResult result = petService.addPet(pet);
        log.info("result:{}", result);
        return ResultTool.success(result);
    }

    @DeleteMapping("/delete")
    public JsonResult delete(String id) {
        log.info("id:{}", id);
        return petService.deletePet(id);
    }

    @PutMapping("/update")
    public JsonResult update(Pet pet) {
        log.info("pet:{}", pet);
        JsonResult result = petService.updatePet(pet);
        log.info("result:{}", result);
        return ResultTool.success(result);
    }

    @GetMapping("/listByPage/{page}/{size}")
    public JsonResult listByPage(@PathVariable("page") int page, @PathVariable("size") int size) {
        log.info("page:{},size:{}", page, size);
        JsonResult result = petService.listByPage(page, size);
        log.info("result:{}", result);
        return ResultTool.success(result);
    }
}
